package IT08;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/*
创建一个HashMap集合，键是学号（String），值是学生对象（Student）。存储三个键值对对象，并遍历
 */
public class HashMapDemo {
    public static void main(String[] args) {
        //创建HashMap集合对象
        HashMap<String,Student> hm = new HashMap<>();
        Student s1 = new Student("林青霞",19);
        Student s2 = new Student("宝斯瓦林",9);
        Student s3 = new Student("瓦工祖贤",109);
        Student s4 = new Student("瓦工祖贤",109);
        hm.put("01",s1);
        hm.put("02",s2);
        hm.put("03",s3);
        hm.put("04",s4);
        Set<Map.Entry<String, Student>> entrySet = hm.entrySet();
        for(HashMap.Entry<String,Student> me: entrySet){
            String key = me.getKey();
            Student value = me.getValue();
            System.out.println(key+":"+value.getName()+","+value.getAge());
        }
    }
}
